package com.java110.mall.cart.bmo.inoutOrder.impl;

import com.java110.mall.cart.bmo.inoutOrder.IGetInoutOrderBMO;
import com.java110.dto.inoutOrder.InoutOrderDto;
import com.java110.intf.cart.IInoutOrderInnerServiceSMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("getInoutOrderBMOImpl")
public class GetInoutOrderBMOImpl implements IGetInoutOrderBMO {

    @Autowired
    private IInoutOrderInnerServiceSMO inoutOrderInnerServiceSMOImpl;

    /**
     * @param inoutOrderDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(InoutOrderDto inoutOrderDto) {


        int count = inoutOrderInnerServiceSMOImpl.queryInoutOrdersCount(inoutOrderDto);

        List<InoutOrderDto> inoutOrderDtos = null;
        if (count > 0) {
            inoutOrderDtos = inoutOrderInnerServiceSMOImpl.queryInoutOrders(inoutOrderDto);
        } else {
            inoutOrderDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) inoutOrderDto.getRow()), count, inoutOrderDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
